package com.augurit.gzcgwsp.ywcmn.service.impl;

import java.util.List;

import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page; 
import org.springside.modules.orm.PropertyFilter;

import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.ywcmn.convert.YwComSjtzsScclConvertor;
import com.augurit.gzcgwsp.ywcmn.dao.YwComSjtzsScclDao;
import com.augurit.gzcgwsp.ywcmn.entity.YwComSjtzsSccl;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjtzsScclService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjtzsScclForm;

@Service
@Transactional
public class YwComSjtzsScclServiceImpl implements IYwComSjtzsScclService{
	@Autowired
	private YwComSjtzsScclDao ywComSjtzsScclDao;

	@Override
	public List<YwComSjtzsScclForm> getList(YwComSjtzsScclForm form) {
//  	用sql查询
  	String sqlString = "select * from YW_COM_SJTZS_SCCL t where t.tplcode = '"+ form.getTplcode() + "' ";
  	if(StringUtils.isNotBlank(form.getAcceptNo())){
		sqlString = sqlString + " and t.Accept_No = '"+form.getAcceptNo()+"'";
	}
  	if(StringUtils.isNotBlank(form.getAcceptNo())){
		sqlString = sqlString + " and t.ajid = "+form.getAjid();
	}
  	SQLQuery sqlQuery = ywComSjtzsScclDao.getSession().createSQLQuery(sqlString).addEntity(YwComSjtzsSccl.class);
  	List<YwComSjtzsSccl> entityList = sqlQuery.list();
  	List<YwComSjtzsScclForm> formList = YwComSjtzsScclConvertor.convertVoListToFormList(entityList);
  	return formList;
  }

	@Override
	public List<YwComSjtzsScclForm> getList(String name, String templateCode) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<YwComSjtzsScclForm> getSjList(YwComSjtzsScclForm form,
			String type) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<YwComSjtzsSccl> getYwComSjcls(String templateCode) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<YwComSjtzsScclForm> search(Page<YwComSjtzsScclForm> page,
			List<PropertyFilter> filters) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<YwComSjtzsScclForm> search(Page<YwComSjtzsScclForm> page,
			YwComSjtzsScclForm form) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(Long... ids) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public YwComSjtzsScclForm get(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save(YwComSjtzsScclForm... forms) {
		if(forms != null)
			for(YwComSjtzsScclForm form : forms)
				this.save(form);
	}
	
	/**
	 * �����������޸ĵ�Form����
	 */
	public void save(YwComSjtzsScclForm form){
		
		if(form != null){
			YwComSjtzsSccl entity = null;
			
			//׼��VO����
			if(form != null && form.getId() != null){
				entity = ywComSjtzsScclDao.get(form.getId());
			}else{
				entity = new YwComSjtzsSccl();
			}
			
			//����ֵת��
			YwComSjtzsScclConvertor.convertFormToVo(form, entity);
			
			//����
			ywComSjtzsScclDao.save(entity);
			
			//����ID����ֵ
			form.setId(entity.getId());
		}
	}
	
	/**
	 * 根据acceptNo、ajid、templateCode删除记录
	 * @param acceptNo
	 * @param ajid
	 * @param templateCode
	 */
	public void deleteByAcceptNoAndAjidAndTemplateCode(String acceptNo,Long ajid,String templateCode){
		String sql = "delete from YW_COM_SJTZS_SCCL t where t.accept_no='"+acceptNo+"' and t.ajid="+ajid+" and t.tplcode='"+templateCode+"'";
		ywComSjtzsScclDao.getSession().createSQLQuery(sql).executeUpdate();
	}

	@Override
	public List<YwComSjtzsSccl> getdataByNo(String acceptNo) {
		String sql=" from YwComSjtzsSccl where acceptNo='"+acceptNo+"'";
		return ywComSjtzsScclDao.find(sql);
	}
}
